package ucapital

import (
	"errors"
)

const (
	DefaultApplyId = 1
	DefaultApplyName = "default_application"
)

type DefaultCapital struct {

}

// 查询机房，涉及到遍历，所以入参为pageNo
func (d *DefaultCapital) QueryRooms(pageNo int) (*RoomData, error) {
	rd := &RoomData{
		NextPageNo: CapitalPageStop,
		TotalCnt: 1,
	}

	rooms := make([]RoomItem, 0, 1)
	rooms = append(rooms, RoomItem{Name: DefaultApplyName})
	rd.Items = rooms
	return rd, nil
}

// 基于ip查机器信息
func (d *DefaultCapital) QueryOneMachine(ip string) (*MachineItem, error) {
	machine := &MachineItem{
		DeviceStatus: "正常",
		OsRelease: "CentOS 6.5",
		AppName: DefaultApplyName,
		IP: ip,
	}

	return machine, nil
}

// 基于ip list查一批机器的信息
func (d *DefaultCapital) QueryMultiMachine(ips []string) ([]MachineItem, error) {
	if len(ips) == 0 {
		return nil, errors.New("input ips is empty")
	}
	ms := make([]MachineItem, 0, len(ips))
	for _, ip := range ips {
		one := MachineItem{
			DeviceStatus: "正常",
			OsRelease: "CentOS 6.5",
			AppName: DefaultApplyName,
			IP: ip,
		}

		ms = append(ms, one)
	}

	return ms, nil
}

func (d *DefaultCapital) QueryRoomMachineCnt(room string) (int, error) {
	return 10, nil
}

func (d *DefaultCapital) QueryRoomMachineList(room string, pageNo int) (*MachineListData, error) {
	rd := &MachineListData{
		RoomName: DefaultApplyName,
		NextPageNo: CapitalPageStop,
		TotalCnt: 0,
		Items: []MachineItem{},
	}

	return rd, nil
}

func init()  {
	cap := new(DefaultCapital)
	CapitalInst.SetChannel(cap)
}

